package com.ferrlo.web.controller;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.ferrlo.model.Project;
import com.ferrlo.model.User;
import com.ferrlo.service.IProjectManager;
import com.ferrlo.service.IUserManager;
import com.ferrlo.utils.RRAppConfig;
import com.renren.api.client.RenrenApiConfig;


@Controller
public class IndexController{

	@Resource(name="userManager")
	private IUserManager userManager;
	@Resource(name="projectManager")
	private IProjectManager projectManager;

	@RequestMapping(value="/index")
	public ModelAndView index(HttpServletRequest request){

		ModelAndView mv = new ModelAndView();
		mv.setViewName("index");
		
		String session_islogin = (String) request.getSession().getAttribute("session_islogin");
		if(session_islogin == null || "".equals(session_islogin)){
			request.getSession().setAttribute("session_islogin", "false");
		}
	
		request.setAttribute("projects", findTopProjects());
		
		return mv;
	}
	

private List<Project> findTopProjects(){
	String dqQuery = "ProjectManager.findAllProject.query";
	List<Project> projects = projectManager.findListByDynamicQuery(dqQuery);
	if (projects.size() <= 4) {
		return projects;
	}else {
		return projects.subList(0, 3);
	}
}

}